package app.lemenu;


import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ScrollView;
import android.widget.TextView;



public class activity2 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {    	
    	super.onCreate(savedInstanceState);    	
    	
    	TextView texto2 = new TextView(this);
    	String texto=null;
    	
    	Cursor cursor;
    	Intent it = getIntent();
    	if (it!= null)
    	{
    		texto = it.getStringExtra("msg").toString();
    	}
    	
    	////////////////////// "Copiando o banco pra armazenamento do aplicativo no telefone"/////
    	
    	 DataBaseHelper myDbHelper = new DataBaseHelper(this);//I got no idea!!!
       
  
         try 
         {
  
         	myDbHelper.createDataBase();
  
         } 
         catch (IOException ioe) 
         {
  
        	 throw new Error("Unable to create database");
  
         }	
         
         
  
         try 
         {  
        	 myDbHelper.openDataBase();  
         }
         catch(SQLException sqle)
         {  
        	 throw sqle;
         }
    	
    	
    	///////////////////// fim da abertura(ou cria��o) do banco /////////////
    	
    	
  		SQLiteDatabase base = myDbHelper.getReadableDatabase(); //pegando o banco
  		
    	cursor = base.query("Content",null , null, null, null, null, null);
    	cursor.moveToFirst(); //resetando o cursor pra primeira posição do set retornado (row 1) 	
    	
    	
    	
    	
    	if(texto.equals("Wiki"))
    	{    	    	
    		texto2.setText(cursor.getString(cursor.getColumnIndex("Wiki"))); //pega campo wiki
    	}    	
    	else
    	{
    		texto2.setText(cursor.getString(cursor.getColumnIndex("Chat"))); //pega campo chat
    	}
    	
    	base.close();
    	myDbHelper.close(); //fechando o banco e o helper
    	
    	
    	texto2.setTextSize(20);
    	
    	ScrollView caixa = new ScrollView(this); //criando frame para scroll
    	caixa.addView(texto2);
    	
    	setContentView(caixa);        
    	
    }
    
    
    
    
}